<extend name="Layout:layout"/>

<block name="css">
	<link rel="stylesheet" href="">

	<style type="text/css">
		.divAddDoc{
			height: auto;
			overflow: hidden;
		}

		#btnAddDoc{
			float: right;
			margin-top: 20px;
		}
	</style>
</block>

<block name="srcjs">
	<script type="text/javascript" src=""></script>
</block>

<block name="content">

		<div class="divAddDoc">
			<h1 style="float: left">学习文档列表</h1>
			<button class="btn btn-primary btn-lg" id="btnAddDoc" data-toggle="modal" data-target="#addDocModal">新增学习文档</button>
		</div>
		<hr>

		<table class="table table-hover">
			<thead>
				<tr>
					<th>#</th>
					<th>文档名称</th>
					<th>XXX</th>
					<th>描述</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody>
				<volist name="docs" id="doc" key="k">
					<tr>
						<td>{$k}</td>
						<td>{$doc.doc_name}</td>
						<td></td>
						<td></td>
						<td>
							<button data-id="{$doc.doc_id}" data-name="{$doc.doc_name}" class="btn btn-warning btn-sm" data-toggle="modal" data-target="#updateDocModal">
							更新
							</button>
							<button data-id="{$doc.doc_id}" class="btn btn-danger btn-sm" data-target="btnDelDoc">删除</button>
						</td>
					</tr>
				</volist>
				

				

			</tbody>
		</table>

		<!-- Modal -->
		<div class="modal fade" id="addDocModal" tabindex="-1" role="dialog" aria-labelledby="addDocModalLabel" aria-hidden="true">
			<div class="modal-dialog modal-lg">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal">
							<span aria-hidden="true">&times;</span>
							<span class="sr-only">Close</span>
						</button>
						<h4 class="modal-title" id="addDocModalLabel">新增学习文档</h4>
					</div>
					<div class="modal-body">

						<form class="form-horizontal" role="form">
							<div class="form-group">
								<label for="doc_name" class="col-sm-2 control-label">文档名字</label>
								<div class="col-sm-10">
									<input type="text" class="form-control" id="doc_name"></div>
							</div>
						</form>

					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
						<button type="button" id="btnSubmitAddDoc" class="btn btn-primary">保存</button>
					</div>
				</div>
			</div>
		</div>

		<!-- Modal -->
		<div class="modal fade" id="updateDocModal" tabindex="-1" role="dialog" aria-labelledby="updateDocModalLabel" aria-hidden="true">
			<div class="modal-dialog modal-lg">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal">
							<span aria-hidden="true">&times;</span>
							<span class="sr-only">Close</span>
						</button>
						<h4 class="modal-title" id="updateDocModalLabel">更新学习文档</h4>
					</div>
					<div class="modal-body">

						<form class="form-horizontal" role="form">

							<div class="form-group">
								<label for="doc_old_name" class="col-sm-2 control-label">原文档名字</label>
								<div class="col-sm-10">
									<input type="text" class="input-read" id="doc_old_name" readonly="true"></div>
							</div>

							<div class="form-group">
								<label for="doc_new_name" class="col-sm-2 control-label">文档名字</label>
								<div class="col-sm-10">
									<input type="text" class="form-control" id="doc_new_name" ></div>
							</div>



						</form>

					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
						<button type="button" id="btnSubmitUpdateDoc" class="btn btn-primary">保存</button>
					</div>
				</div>
			</div>
		</div>
</block>

<block name="customjs">
	<include file="index.js" />

	<script type="text/javascript">
	$(function(){


		var doc_id = -1;

		$("button[data-target='#updateDocModal']").click(function(){
			$("#doc_old_name").val($(this).attr("data-name"));
			doc_id = $(this).attr("data-id");
		});


		$("#btnSubmitUpdateDoc").click(function(){

			var sendData = {
				"doc_id" : doc_id,
				"doc_name" : $("#doc_new_name").val()
			};
			//console.log(sendData);
			$.post("{:U('updatePicDoc')}", sendData).done(function(responseData){
				if(responseData.status == 1){
					alert(responseData.info);
					location.href = responseData.jumpUrl;
				}else{
					alert(responseData.info);
				}
			});

		});


		$("#btnSubmitAddDoc").click(function(){
			var sendData = {
				"doc_name" : $("#doc_name").val()
			};

			$.post("{:U('addPicDoc')}", sendData).done(function(responseData){
				if(responseData.status == 1){
					alert(responseData.info);
					location.href = responseData.jumpUrl;
				}else{
					alert(responseData.info);
				}
			});
		});



		$("button[data-target='btnDelDoc']").click(function(){
			var sendData = {"id" : $(this).attr("data-id")};
			$.post("{:U('delPicDoc')}", sendData).done(function(responseData){
				if(responseData.status == 1){
					alert(responseData.info);
					location.href = responseData.jumpUrl;
				}else{
					alert(responseData.info);
				}
			});

		});

	});
	</script>
</block>